package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.MachineDAO;
import com.zerosky.crm.po.Machine;
import com.zerosky.crm.service.MachineService;
import com.zerosky.crm.util.PageInfo;

@Service(value = "machineService")
public class MachineServiceImpl implements MachineService {
	@Autowired
	private MachineDAO MachineDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public List<Machine> getMachineAllList(Map map) {
		return MachineDao.getMachineAllList(map);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Machine> getMachinePageInfoList(Map map) {
		int begin = (((int) map.get("page") - 1) * (int) map.get("limit"));
		int pageSize = (int) map.get("limit");
		PageInfo<Machine> page = new PageInfo<Machine>();
		// 写入数据
		map.put("pageNo", begin);
		map.put("pageSize", pageSize);
		List<Machine> list = MachineDao.getMachineAllList(map);
		page.setList(list);

		Integer count = MachineDao.countMachine(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Machine getMachineById(String MachineId) {
		return MachineDao.getMachineById(MachineId);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void addMachine(Machine Machine) {
		MachineDao.addMachine(Machine);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void updateMachine(Machine Machine) {
		MachineDao.updateMachine(Machine);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteMachineById(String MachineId) {
		MachineDao.deleteMachineById(MachineId);
	}
}
